import {onMounted, ref} from 'vue'
import {getTopCategoryAPI} from '@/apis/category.js'
import { useRoute, onBeforeRouteUpdate } from 'vue-router'


export function useCategory(){
    const categoryDate = ref([])
    const route = useRoute()
const getCategoryDate = async (id = route.params.id ) => {
const {data} = await getTopCategoryAPI(id)
categoryDate.value = data.result
console.log(categoryDate.value)
}
onMounted(()=>{getCategoryDate()})

onBeforeRouteUpdate((to) =>{
    getCategoryDate(to.params.id)
})
return categoryDate

}
